<template>
  <div>
    <h1 style="text-align: center">肌力2</h1>
    <el-card class="box-card">
      <el-table
        :data="pgForm"
        :span-method="objectSpanMethod"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column
          prop="limb"
          label=""
          width="180">
        </el-table-column>
        <el-table-column
          prop="part"
          label="部位">
        </el-table-column>
        <el-table-column prop="level_left" label="左" fixed="right" width="180" align="center">
          <template slot-scope="scope">
            <el-select v-model="scope.row.level_left" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="level_right" label="右" fixed="right" width="180" align="center">
          <template slot-scope="scope">
            <el-select v-model="scope.row.level_right" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
      </el-table>
  </el-card>
  </div>
</template>

<script>
export default {
  name: "strength2_lower",
  title: "肌力2(下肢)",
  created() {
    if(this.istrans){
      this.pgForm=this.fromdata
    }
  },
  props:{
    fromdata:{},
    istrans:false,
  },
  data() {
    return {
      pgForm: [{
        limb: '下肢',
        part: '髋',
        level_left: '',
        level_right: ''
      }, {
        limb: '下肢',
        part: '腿',
        level_left: '',
        level_right: ''
      }, {
        limb: '下肢',
        part: '踝',
        level_left: '',
        level_right: ''
      }],
      options: [{
        value: '选项1',
        label: '0级'
      }, {
        value: '选项2',
        label: '1级'
      }, {
        value: '选项3',
        label: '2级'
      }, {
        value: '选项4',
        label: '3级'
      }, {
        value: '选项5',
        label: '4级'
      }, {
        value: '选项6',
        label: '5级'
      }],
    };
  },
  methods: {

    //合并方法
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 0) {
        //合并相同的名字
        let nameSpan = this.getSpanNumber(this.pgForm, "limb");
        return {
          rowspan: nameSpan[rowIndex],
          colspan: 1,
        };
      }
    },
    //获取要合并的行数
    getSpanNumber(data, prop) {
      //data要处理的数组，prop要合并的属性，比如name

      //数组的长度，有时候后台可能返回个null而不是[]
      let length = Array.isArray(data) ? data.length : 0;
      if (length > 0) {
        //用于标识位置
        let position = 0;
        //用于对比的数据
        let temp = data[0][prop];
        //要返回的结果
        let result = [1];
        //假设数据是AABCC，我们的目标就是返回20120
        for (let i = 1; i < length; i++) {
          if (data[i][prop] == temp) {
            //标识位置的数据加一
            result[position] += 1;
            //当前位置添0
            result[i] = 0;
          } else {
            //不相同时，修改标识位置，该位置设为1，修改对比值
            position = i;
            result[i] = 1;
            temp = data[i][prop];
          }
        }
        //返回结果
        return result;
      } else {
        return [0];
      }
    },

    del() {
      this.$emit('del', '');
    }
  }
}
</script>

<style scoped>
</style>
